<template>
  <a-modal :open="open" width="700px" :title="title" centered @ok="onOk" @cancel="onCancel">
    <div class="flex justify-between">
      <div class="">
        <BaseTitle title="基础信息" />
        <PatientInfoForm v-model:value="patientState" type="edit" />
      </div>
    </div>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post, get } from '@/utils/request'

const emit = defineEmits(['update:open', 'success'])
const props = defineProps({
  open: {
    type: Boolean,
    default: false
  },
  title: {
    type: String,
    default: '更改登记'
  },
  rowData: {
    type: Object,
    default: () => ({})
  }
})

const patientState = ref({}) // 患者信息

watch(
  () => props.open,
  (val) => {
    if (val) {
      getUser(props.rowData.brId)
    } else {
      patientState.value = {}
    }
  }
)
const getUser = async (e) => {
  const data = await get('/common/patient/getPatientInfo?br_id=' + e)
  patientState.value = data.data
}

const onCancel = () => {
  emit('update:open', false)
}
const onOk = async () => {
  const data = await post('/common/patient/savePatientInfo', patientState.value)
  if (data.code !== 0) return message.error(data.msg)
  message.success(data.msg)
  emit('success')
}
</script>
